package com.huitu.whht.base.core.api.gb.table;

import com.huitu.api.rest.AbstractApiResource;
import com.huitu.commons.PageUtils;
import com.huitu.whht.api.core.common.response.ApiResultBuilder;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiResource;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiService;
import com.huitu.whht.api.core.common.response.StatusRespBuilder;

import com.huitu.whht.base.core.api.gb.table.entities.GbTableMetaInfo;

import com.huitu.whht.base.core.api.gb.table.entities.GbTableMetaInfoQo;
import com.huitu.whht.base.core.api.gb.table.service.IGbTableMetaInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * 说明: 公报表相关详情表API,表名称: T_WHHT_GB_TABLE_META_INFO <br/>
 * 日期: 2019-04-11
 * @author LiuCW
 */
@Component
@SzyCoreApiResource
@Path("gb/table/meta/info")
public class GbTableMetaInfoResource extends AbstractApiResource {

    private static final Logger LOGGER = LoggerFactory.getLogger(GbTableMetaInfoResource.class);

    private static final String UUID = "405911fa-ec81-4adb-b694-59a2f94a4b72";

    @Override
    public String getUUID() {
        return UUID;
    }

    @Autowired
    @SzyCoreApiService
    IGbTableMetaInfoService gbTableMetaInfoService;

    /**
     * @api {get} gb/table/meta/info/{gbTable} [R][G]根据主键查询
     * @apiDescription [G]根据主键查询T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)select by primary key
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiSampleRequest gb/table/meta/info/T_WHHT_GB_CITY_WATER_PRICE
     * @apiParam   {String}         gbTable            【必须】水资源公报表名
     * @apiSuccess {String}         gbTable            水资源公报表名
     * @apiSuccess {String}         gbTableInfo        水资源公报表中文名称
     * @apiSuccess {Double}         gbNum              公报表序号
     * @apiSuccess {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     *  }
     * }
     * @apiUse exceptions
     */
    @GET
    @Path("{gbTable}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectByPrimaryKey(@PathParam("gbTable") String gbTable) {
        LOGGER.info("根据主键查询 公报表相关详情表,参数 gbTable:{}", gbTable);
        return Response.ok(ApiResultBuilder.create(this, gbTableMetaInfoService.selectByPrimaryKey(gbTable))).build();
    }

    /**
     * @api {post} gb/table/meta/info/list [R][G]根据条件查询
     * @apiDescription [G]根据条件查询T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)select by filter
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiSampleRequest gb/table/meta/info/list
     * @apiParam   {String}         gbTable            水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNumMin           (最小)公报表序号
     * @apiParam   {Double}         gbNumMax           (最大)公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {String}         gbTable            水资源公报表名
     * @apiSuccess {String}         gbTableInfo        水资源公报表中文名称
     * @apiSuccess {Double}         gbNum              公报表序号
     * @apiSuccess {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     *  }]
     * }
     *
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     *  }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectList(GbTableMetaInfoQo filter) {
        PageUtils.startPageFromRang();
        LOGGER.info("根据条件查询 公报表相关详情表,参数 GbTableMetaInfoQo:{}", filter);
        return Response.ok(ApiResultBuilder.create(this, gbTableMetaInfoService.selectList(filter))).build();
    }

    /**
     * @api {put} gb/table/meta/info [C][G]新增数据
     * @apiPrivate
     * @apiDescription [G]新增T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)add data
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiParam   {String}         gbTable            【必须】水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNum              公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             1:新增成功;0:新增失败.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据,通常包含新增数据的主键值
     * @apiSampleRequest gb/table/meta/info
     * @apiSuccessExample 新增成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":{
     *   "gbTable": "T_WHHT_GB_CITY_WATER_PRICE"
     *      }
     *   }
     * }
     @apiSuccessExample 新增失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":{
     *   "gbTable": "T_WHHT_GB_CITY_WATER_PRICE"
     *      }
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     * }
     * @apiUse exceptions
     */
    @PUT
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insert(GbTableMetaInfo record) {
        LOGGER.info("新增 公报表相关详情表,参数 GbTableMetaInfo:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.insert(gbTableMetaInfoService.insertSelective(record),record))).build();
    }

    /**
     * @api {post} gb/table/meta/info/insertBatch [C][G]批量新增数据
     * @apiPrivate
     * @apiDescription [G]批量新增T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)addBatch data
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiParam   {String}         gbTable            【必须】水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNum              公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             1:新增成功;0:新增失败.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据,通常包含新增数据的主键值
     * @apiSampleRequest gb/table/meta/info/insertBatch
     * @apiSuccessExample 新增成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":{
     *   "gbTable": "T_WHHT_GB_CITY_WATER_PRICE"
     *      }
     *   }
     * }
     @apiSuccessExample 新增失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":{
     *   "gbTable": "T_WHHT_GB_CITY_WATER_PRICE"
     *      }
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * [{
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     * }]
     * @apiUse exceptions
     */
    @POST
    @Path("insertBatch")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response insertBatch(List<GbTableMetaInfo> recordList) {
        LOGGER.info("批量新增 公报表相关详情表,参数 GbTableMetaInfo:[]", recordList);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.insert(gbTableMetaInfoService.insertBatch(recordList),recordList))).build();
    }

    /**
     * @api {put} gb/table/meta/info/{gbTable}/update [U][G]根据主键修改
     * @apiPrivate
     * @apiDescription [G]根据主键修改T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)update data
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiParam   {String}         gbTable            【必须】水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNum              公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest gb/table/meta/info/T_WHHT_GB_CITY_WATER_PRICE/update
     * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("{gbTable}/update")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response update(@PathParam("gbTable") String gbTable, GbTableMetaInfo record) {
        record.setGbTable(gbTable);
        LOGGER.info("根据主键修改 公报表相关详情表,参数 GbTableMetaInfo:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(gbTableMetaInfoService.updateByPrimaryKey(record)))).build();
    }

    /**
     * @api {put} gb/table/meta/info/{gbTable}/update-selective [U][G]根据主键修改(只修改非null字段)
     * @apiPrivate
     * @apiDescription [G]根据主键修改T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据,只修改非null字段
     * @apiName (generate)update selected data
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiParam   {String}         gbTable            水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNum              公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest gb/table/meta/info/T_WHHT_GB_CITY_WATER_PRICE/update-selective
     * * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * {
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     * }
     * @apiUse exceptions
     */
    @PUT
    @Path("{gbTable}/update-selective")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response updateSelective(@PathParam("gbTable") String gbTable, GbTableMetaInfo record) {
        record.setGbTable(gbTable);
        LOGGER.info("根据主键修改(只修改非null字段) 公报表相关详情表,参数 GbTableMetaInfo:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(gbTableMetaInfoService.updateByPrimaryKeySelective(record)))).build();
    }

    /**
     * @api {post} gb/table/meta/info/updateBatch [U][G]根据主键批量修改(只修改非null字段)
     * @apiPrivate
     * @apiDescription [G]根据批量主键修改T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据,只修改非null字段
     * @apiName (generate)updateBatch selected data
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiParam   {String}         gbTable            水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNum              公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             1:修改成功;0:要修改的数据不存在(可能已被删除)
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSampleRequest  gb/table/meta/info/updateBatch
     * * @apiSuccessExample 修改成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 修改失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiParamExample {json} 请求示例:
     * [{
     * "gbTable": "T_WHHT_GB_CITY_WATER_PRICE",
     * "gbTableInfo": "城市水价信息表",
     * "gbNum": 4,
     * "gbTableProperties": null
     * }]
     * @apiUse exceptions
     */
    @POST
    @Path("updateBatch")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response updateBatch(List<GbTableMetaInfo> record) {
        LOGGER.info("根据主键批量修改(只修改非null字段) 公报表相关详情表,参数 GbTableMetaInfo:{}", record);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.update(gbTableMetaInfoService.updateBatch(record)))).build();
    }

    /**
     * @api {delete} gb/table/meta/info/{gbTable} [D][G]根据主键删除
     * @apiPrivate
     * @apiDescription [G]根据主键删除T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)delete by primary key
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiSampleRequest gb/table/meta/info/T_WHHT_GB_CITY_WATER_PRICE
     * @apiParam   {String}         gbTable            【必须】水资源公报表名
     * @apiSuccess {Integer}        status             1:删除成功;0:要删除的数据不存在(可能已被删除).
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("{gbTable}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response delete(@PathParam("gbTable") String gbTable) {
        LOGGER.info("根据主键删除 公报表相关详情表,参数 gbTable:{}", gbTable);
        Integer rows = gbTableMetaInfoService.deleteByPrimaryKey(gbTable);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }

    /**
     * @api {delete} gb/table/meta/info/by-filter [D][G]根据条件删除
     * @apiPrivate
     * @apiDescription [G]根据条件删除T_WHHT_GB_TABLE_META_INFO(公报表相关详情表)数据
     * @apiName (generate)delete by filter
     * @apiGroup GB_TABLE_META_INFO-公报表相关详情表
     * @apiVersion 1.0.0
     * @apiSampleRequest gb/table/meta/info/by-filter
     * @apiParam   {String}         gbTable            水资源公报表名
     * @apiParam   {String}         gbTableInfo        水资源公报表中文名称
     * @apiParam   {Double}         gbNumMin           (最小)公报表序号
     * @apiParam   {Double}         gbNumMax           (最大)公报表序号
     * @apiParam   {String}         gbTableProperties  1：添加总计行，0：不添加总计行
     * @apiSuccess {Integer}        status             通常1或者>1:删除成功;0:没有符合条件的数据.
     * @apiSuccess {String}         message            成功/失败消息内容
     * @apiSuccess {Object}         data               额外返回的数据
     * @apiSuccessExample 删除成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":1,
     * "message":"成功",
     * "data":null
     *   }
     * }
     * @apiSuccessExample 删除失败:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "status":0,
     * "message":"失败",
     * "data":null
     *   }
     * }
     * @apiUse exceptions
     */
    @DELETE
    @Path("by-filter")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response deleteByFilter(GbTableMetaInfoQo filter) {
        LOGGER.info("根据条件删除 公报表相关详情表,参数 GbTableMetaInfoQo:{}", filter);
        Integer rows = gbTableMetaInfoService.deleteByFilter(filter);
        return Response.ok(ApiResultBuilder.create(this, StatusRespBuilder.delete(rows))).build();
    }
}
